﻿using ZYCommon;
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using Bifrost;

namespace TextEditor
{
    
    /// <summary>
    /// 文本块属性设置
    /// </summary>
    public class DivTagProviderUpdate : SmartTagProvider
    {
        public override void GetCommands(ArrayList myList)
        {
            ZYTextDiv parent = base.OwnerDocument.Content.CurrentElement.Parent as ZYTextDiv;
            if (parent != null)
            {
                myList.Add(new SmartTagItem(this, 0, "修改"));
            }
        }

        public override Point GetPos()
        {
            ZYTextDiv parent = base.OwnerDocument.Content.CurrentElement.Parent as ZYTextDiv;
            if (parent != null)
            {
                return new Point(-base.OwnerControl.SmartTagSize() + 550, parent.RealTop);
            }
            return Point.Empty;
        }

        public override bool HandleCommand(SmartTagItem item)
        {
            ZYTextDiv parent = base.OwnerDocument.Content.CurrentElement.Parent as ZYTextDiv;
            if (parent != null)
            {
                switch (item.ID)
                {
                    case 0:
                        {
                            App.Msg("埃保常");
                            return true;
                        }
                }
            }
            return false;
        }

        public override bool isEnable()
        {
            if ((base.OwnerDocument.Content.SelectLength == 0) && (base.OwnerDocument.Content.CurrentElement != null))
            {
                ZYTextDiv parent = base.OwnerDocument.Content.CurrentElement.Parent as ZYTextDiv;
              
                if (base.OwnerDocument.Content.PreElement != null)
                {
                    if (((parent != null) && (parent != base.OwnerDocument.DocumentElement)) && base.OwnerDocument.Content.PreElement.Parent != parent)
                    {
                        return true;
                    }
                }
                else
                {
                    if(((parent != null) && (parent != base.OwnerDocument.DocumentElement)) && base.OwnerDocument.Content.PreElement==null)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public override int ImageIndex
        {
            get
            {
                return 0x10;
            }
        }
    }
}

